<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>loop-iv (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="loop-iv (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="loop-iv (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Loop-Analysis-and-Representation.html" rel="up" title="Loop Analysis and Representation">
<link href="Number-of-iterations.html" rel="next" title="Number of iterations">
<link href="Scalar-evolutions.html" rel="prev" title="Scalar evolutions">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="loop_002div">
<div class="nav-panel">
<p>
Next: <a href="Number-of-iterations.html" accesskey="n" rel="next">Number of iterations analysis</a>, Previous: <a href="Scalar-evolutions.html" accesskey="p" rel="prev">Scalar evolutions</a>, Up: <a href="Loop-Analysis-and-Representation.html" accesskey="u" rel="up">Analysis and Representation of Loops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="IV-analysis-on-RTL"><span>16.6 IV analysis on RTL<a class="copiable-link" href="#IV-analysis-on-RTL"> &para;</a></span></h3>
<a class="index-entry-id" id="index-IV-analysis-on-RTL"></a>

<p>The induction variable on RTL is simple and only allows analysis of
affine induction variables, and only in one loop at once.  The interface
is declared in <samp class="file">cfgloop.h</samp>.  Before analyzing induction variables
in a loop L, <code class="code">iv_analysis_loop_init</code> function must be called on L.
After the analysis (possibly calling <code class="code">iv_analysis_loop_init</code> for
several loops) is finished, <code class="code">iv_analysis_done</code> should be called.
The following functions can be used to access the results of the
analysis:
</p>
<ul class="itemize mark-bullet">
<li><code class="code">iv_analyze</code>: Analyzes a single register used in the given
insn.  If no use of the register in this insn is found, the following
insns are scanned, so that this function can be called on the insn
returned by get_condition.
</li><li><code class="code">iv_analyze_result</code>: Analyzes result of the assignment in the
given insn.
</li><li><code class="code">iv_analyze_expr</code>: Analyzes a more complicated expression.
All its operands are analyzed by <code class="code">iv_analyze</code>, and hence they must
be used in the specified insn or one of the following insns.
</li></ul>

<p>The description of the induction variable is provided in <code class="code">struct
rtx_iv</code>.  In order to handle subregs, the representation is a bit
complicated; if the value of the <code class="code">extend</code> field is not
<code class="code">UNKNOWN</code>, the value of the induction variable in the i-th
iteration is
</p>
<div class="example smallexample">
<pre class="example-preformatted">delta + mult * extend_{extend_mode} (subreg_{mode} (base + i * step)),
</pre></div>

<p>with the following exception:  if <code class="code">first_special</code> is true, then the
value in the first iteration (when <code class="code">i</code> is zero) is <code class="code">delta +
mult * base</code>.  However, if <code class="code">extend</code> is equal to <code class="code">UNKNOWN</code>,
then <code class="code">first_special</code> must be false, <code class="code">delta</code> 0, <code class="code">mult</code> 1
and the value in the i-th iteration is
</p>
<div class="example smallexample">
<pre class="example-preformatted">subreg_{mode} (base + i * step)
</pre></div>

<p>The function <code class="code">get_iv_value</code> can be used to perform these
calculations.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Number-of-iterations.html">Number of iterations analysis</a>, Previous: <a href="Scalar-evolutions.html">Scalar evolutions</a>, Up: <a href="Loop-Analysis-and-Representation.html">Analysis and Representation of Loops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
